﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Interfaces.Update_Interfaces;
using Presenters.Inherited_Presenters;
using Model.Query_Model;
using Presenters.Managers;

namespace Presenters.Update_Presenters
{
    public class RoadUpdatePresenter:OperationStatus
    {
        private IRoadUpdateView view = null;
        public RoadOutput road = null;

        public RoadUpdatePresenter(IRoadUpdateView view)
        {
            this.view = view;
        }

        public void SendDataToView()
        {
            view.fromCity = road.fromCity;
            view.fromCountry = road.fromCountry;
            view.toCity = road.toCity;
            view.toCountry = road.toCountry;
            view.typeRoad = road.typeRoad;
        }

        private void Reconstruct()
        {
            road.fromCity = view.fromCity;
            road.fromCountry = view.fromCountry;
            road.toCity = view.toCity;
            road.toCountry = view.toCountry;
            road.typeRoad = view.typeRoad;
        }

        public void Update()
        {
            nameOperation = "Aktualizacja trasy";
            try
            {
                Reconstruct();
                RoadManager manager = new RoadManager();
                manager.RoadUpdate(road);
                view.ShowSuccess();
            }
            catch (Exception ex)
            {
                exception = ex.Message;
                view.ShowError();
            }
        }
    }
}
